<%@ page import="org.jeecgframework.web.util.StaticValue"%>
<%@ page language="java" import="java.util.*" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>报价单-发送</title>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
</head>
<body>
<t:formvalid formid="formobj" dialog="false" usePlugin="password" layout="table" action="cbsQuotationController.do?doSendMail" beforeSubmit="checkTaskHandle" tiptype="3" callback="callBackSendMail">
<input type="hidden" name="quotationId" value="${quotation.id }">
<input type="hidden" name="taskId" value="${task.id }">
<input type="hidden" name="instId" value="${instId }">
<input type="hidden" name="busId" value="${bus.id }">
<input type="hidden" name="actionResult" id="actionResult">
	<div class="subtitle">
		<p>基础信息</p>
		<c:if test="${isDetail eq '2' && btnFlag eq '0'}">
		 &nbsp; &nbsp; &nbsp;<a class="easyui-linkbutton" href="cbsQuotationController.do?copyQuotation&id=${quotation.id }" style="margin:auto;" >复制报价单</a>
		 &nbsp; &nbsp; &nbsp;<a class="easyui-linkbutton" href="cbsQuotationController.do?dowQuotaiton&id=${quotation.id }" style="margin:auto;" >下载报价单</a>
		 </c:if>
        <c:if test="${canDown eq '1'}">
            &nbsp; &nbsp; &nbsp;<a class="easyui-linkbutton" href="cbsQuotationController.do?dowQuotaiton&id=${quotation.id }" style="margin:auto;" >下载报价单</a>
        </c:if>
        <c:if test="${btnFlag eq '3'}">
            &nbsp; &nbsp; &nbsp;<a class="easyui-linkbutton" href="cbsQuotationController.do?dowQuotaiton&id=${quotation.id }" style="margin:auto;" >下载报价单</a>
        </c:if>
		<table class="nobordertable noborder">
				<tr>
					<td class="al_r" width="20%">
						<label>报价单编号:</label>
					</td>
					<td width="20%">
							${quotation.quotationNum }
					</td>
					<td class="al_r" width="30%">
					</td>
					<td width="30%">
					</td>
				</tr>
				<tr>
					<td class="al_r" width="20%">
						<label>客户类型:</label>
					</td>
					<td width="20%">
							${bus.clientType == 0?'客户':'第三方' }
					</td>
					<td class="al_r" width="30%">
						<c:if test="${bus.clientType != 0 }"><label >采购方:</label></c:if>
					</td>
					<td width="30%">
						<c:if test="${bus.clientType != 0 }">${bus.procurement.departname }</c:if>
					</td>
				</tr>
				<tr>
				
					<td class="al_r">
						<label>影院名称:</label>
					</td>
					<td>
						${bus.cinema.name }
					</td>
					<td class="al_r">
						<label>影院地址:</label>
					</td>
					<td>
						<span id="cinemaAddr">${bus.cinema.address }</span>
					</td>
				</tr>
				<tr>
					<td class="al_r">
						<label>所属机构:</label>
					</td>
					<td>
						<span id="departName">${bus.cinema.belongOrg.departname }</span>
					</td>
					<td class="al_r">
						<label>影院所属省市:</label>
					</td>
					<td>
						<span id="city">
							${bus.cinema.province.territoryName}
							<c:if test="${not empty bus.cinema.city }">,${bus.cinema.city }</c:if>
						</span>
					</td>
				</tr>
				<tr>
					<td class="al_r">
						<label>联系人名称:</label>
					</td>
					<td>
						${bus.contactName }
					</td>
					<td class="al_r">
						<label>联系人电话:</label>
					</td>
					<td>
						<span id="phone">${bus.contactPhone }</span>
					</td>
				</tr>
				<tr>
					<td class="al_r">
						<label>联系人邮箱：</label>
					</td>
					<td>
						<span id="mail">${bus.contactMail }</span>
					</td>
					<td class="al_r">
						<label>传真:</label>
					</td>
					<td>
						<span id="fax">${bus.contactFax }</span>
					</td>
				</tr>
				<tr>
					<td class="al_r">
						<c:if test="${bus.clientType == 0 }"><label>服务地点：</label></c:if>
					</td>
					<td>
						<c:if test="${bus.clientType == 0 }">${bus.servicePlace }</c:if>
					</td>
					<td class="al_r">
						<c:if test="${bus.clientType == 0 }"><label>是否需要上门服务:</label></c:if>
					</td>
					<td>
						<c:if test="${bus.clientType == 0 }">${bus.isOnsiteServices eq '0'?'否':'是' }</c:if>
					</td>
				</tr>
				<tr>
				  <td class="al_r">
				  		<label>保修期:</label>
				  </td>
				  <td colspan="3">
				  	${bus.warranty }
				  </td>
				</tr>
				<tr>
				  <td class="al_r">
				  		<c:if test="${bus.clientType == 0 }"><label>服务前提:</label></c:if>
				  </td>
				  <td colspan="3">
				  	<c:if test="${bus.clientType == 0 }">${bus.servicesPremise }</c:if>
				  </td>
				</tr>
				<tr>
				  <td class="al_r">
				  	<c:if test="${bus.clientType != 0 }"><label>备注:</label></c:if>
				  </td>
				  <td colspan="3">
				  	<c:if test="${bus.clientType != 0 }">${bus.comment }</c:if>
				  	
				  </td>
				</tr>
			</table>
	</div>
	
	<div class="subtitle" >
			<p>订购明细</p> &nbsp;
			折扣率：${quotation.disCount }%
	</div>
	  <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable" id="partInfoTab">
	  	<tr align="center">
	       <td width="12%" >配件号</td>
	       <td width="16%">中文描述</td>
	       <td width="12%">单位</td>
	       <td width="12%">数量</td>
	       
	       <td width="12%">零售指导价</td>
	       <td width="12%">折扣价</td>
	       <td width="12%">最终价</td>
	       <td width="12%">价格小计CNY（折扣后）</td>
	       
	     </tr>
	     <c:forEach items="${quotation.quotationDetailList }" var="detail" varStatus="a">
	     	<tr align="center" style="background-color: #FFFFFF;">
				<td>${detail.procurementPart.partInfo.partNo }</td>
				<td>${detail.procurementPart.partInfo.chineseDes }</td>
				<td>${detail.procurementPart.partInfo.marketUnit }</td>
				<td>${detail.num }</td>
				<td>¥<fmt:formatNumber value="${detail.unitPrice }"  type="number"/></td>
				<td>¥<fmt:formatNumber value="${detail.disCountPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${detail.lastPrice }" type="number"/></td>
				<td>¥<fmt:formatNumber value="${detail.total}" type="number"/></td>
			 </tr>
	     </c:forEach>
	     <c:if test="${bus.isOnsiteServices eq '1' }">
	     	<tr align="center" style="background-color: #FFFFFF;">
	     		<td>上门服务费</td>
				<td>人工费</td>
				<td>EA</td>
				<td>${quotation.manpowerNumber }</td>
				<td>¥<fmt:formatNumber value="${quotation.manpowerPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${quotation.manpowerPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${quotation.manpowerPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${quotation.manpowerNumber * quotation.manpowerPrice}" type="number"/></span>
				</td>
	     	</tr>
	     	<tr align="center" style="background-color: #FFFFFF;">
	     		<td></td>
				<td>差旅费</td>
				<td>EA</td>
				<td>${quotation.travelNumber }</td>
				<td>¥<fmt:formatNumber value="${quotation.travelPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${quotation.travelPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${quotation.travelPrice}" type="number"/></td>
				<td>¥<fmt:formatNumber value="${quotation.travelNumber * quotation.travelPrice}" type="number"/></td>
	     	</tr>
	     </c:if>
	     <tr align="center" style="background-color: #FFFFFF;">
	     	<td>合计</td>
	     	<td></td>
	     	<td></td>
	     	<td></td>
	     	<td></td>
	     	<td></td>
	     	<td></td>
	     	<td>¥<fmt:formatNumber value="${quotation.total}" type="number"/></td>
	     </tr>
	  </table>
       
	<div class="subtitle" >
		<p>相关设备</p> &nbsp;
	</div>
	  <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable" id="equipmentTab">
	     <tr align="center">
	       <td>设备SN</td>
	       <td>型号</td>
	       <td>机型</td>
	       <td>发货日期</td>
	       <td>安装日期</td>
	       <td>保期截至日期</td>
	     </tr>
	     
	     <c:forEach items="${quotation.note.paertEsList }" var='paertEs'>
			<tr align="center" style="background-color: #FFFFFF;">
				<td>${paertEs.equipmentSpare.sn }</td>
				<td>${paertEs.equipmentSpare.item }</td>
				<td>${paertEs.equipmentSpare.type.typeDesc }</td>
				<td><fmt:formatDate value="${paertEs.equipmentSpare.sendDate }" pattern="yyyy-MM-dd"/></td>
				<td><fmt:formatDate value="${paertEs.equipmentSpare.installDate }" pattern="yyyy-MM-dd"/></td>
				<td><fmt:formatDate value="${paertEs.equipmentSpare.repairEndDate }" pattern="yyyy-MM-dd"/></td>
			</tr>		     
	     </c:forEach>
	  </table>
	<div class="subtitle" >
		<p>审批记录</p> &nbsp;
	</div>
	  <table style="margin-top: 20px; line-height: 35px;" cellpadding="0" cellspacing="1" class="formtable" >
	     <tr align="center">
	       <td>审批人</td>
	       <td>审批时间</td>
	       <td>操作结果</td>
	     </tr>
	     
	     <c:forEach items="${recordList }" var='record'>
			<tr align="center" style="background-color: #FFFFFF;">
				<td>${record.tsUser.realName }</td>
				<td><fmt:formatDate value="${record.createDate }" pattern="yyyy-MM-dd HH:mm"/></td>
				<td>${record.remark }</td>
			</tr>
	     </c:forEach>
	  </table>
	  <c:if test="${isDetail ne '2' }">
		<c:choose>
			<c:when test="${quotation.type eq '2' && task.taskDefinitionKey eq 'taskNode1'}">
				<div style="text-align: center;margin: 10px;">
					<a class="easyui-linkbutton" onclick="$('#actionResult').val(0);$('#formobj').submit();">同意</a>&nbsp;&nbsp;&nbsp;&nbsp;
					<a class="easyui-linkbutton" onclick="$('#actionResult').val(1);reject();">驳回</a>
				</div>
			</c:when>
			<c:otherwise>
				<div style="text-align: center;margin: 50px;">
					<div  style="margin-bottom: 50px;">
						<span>邮件抄送人:</span>
						<textarea rows="2" cols="105" name="copyPerson" id="copyPerson" ajaxurl="cbsQuotationController.do?validEmail"></textarea><span class="Validform_checktip">多人请用,分割(符号请符合要求)</span><br/>
					</div>
					<a class="easyui-linkbutton" onclick="sendSubmit()">确认发送报价单</a>
				</div>
			</c:otherwise>
		</c:choose>
	</c:if>
</t:formvalid>
</body>

<script type="text/javascript">
var isSend = false;
function sendSubmit(){
    if(!isSend){
        var mail = $('#copyPerson').val();
        if(mail != ''){
            $('#copyPerson').attr('dataType','*');
        }else{
            $('#copyPerson').removeAttr('dataType');
        }
        $('#formobj').submit();
        isSend = true;
    }else{
        top.tip("请勿重复提交");
        return;
    }
}

function checkTaskHandle(){
	var taskId = '${task.id}';
	$.ajax({
	    url: "cbsProcurementNoteController.do?checkTaskHandle",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: false, //请求是否异步，默认为异步，这也是ajax重要特性
	    data: { "taskId": taskId },    //参数值
	    type: "post",   //请求方式
	    success: function(data) {
	       	if(data.msg == 'n'){
	       		top.tip("操作失败,该任务已被办理");
	       		//刷新列表
	       		var win = frameElement.api.opener;
	       		win.reloadTable();
	       		frameElement.api.close();
	       		return false;
	       	}else{
	       		return true;
	       	}
	    }
	});
}

function callBackSendMail(data){
	if(isSend){
		 $.ajax({
             type: "POST",
             url: "cbsQuotationController.do?realSendMail",
             data: {quotationId:'${quotation.id}'}
         });
	}
	var win = frameElement.api.opener;
		win.reloadTable();
		setTimeout('frameElement.api.close();',500);
}

function reject(){
	var url = "cbsProcurementNoteController.do?goRejectPage&url=cbsQuotationController.do?doSendMail-taskId=${task.id }-busId=${bus.id}-instId=${instId}-quotationId=${quotation.id}-actionResult="+$('#actionResult').val();;
	openRejectWin(url);
}
function openRejectWin(url){
	W.$.dialog({
		content: 'url:'+url,
		lock : true,
		width:500,
		//zIndex:1990,
		height:200,
		parent:windowapi,
		title:'原因',
		opacity : 0.3,
		cache:false,
	    ok: function(){
	    	iframe = this.iframe.contentWindow;
	    	iframe.$('#formobj').submit();
			return false;
	    },
	    cancelVal: '关闭',
	    cancel: true /*为true等价于function(){}*/
	}).zindex();
}
</script>
</html>